package com.zhuzg.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RequestMapping("testa")
@RestController
public class TestaController {

    @Value("${mytest.mykey}")
    String mykey;

    @RequestMapping("strjoin")

    public String strJoing(@RequestParam("stra") String stra,@RequestParam("strb") String strb){
        new HashMap<>();

        System.out.printf("属性文件当中配置内容是："  + mykey);
        return stra + ":" + strb;
    }

    @SentinelResource(value="testLimit",blockHandler="exceptionHandler",fallback = "getByIdfallback")
    @RequestMapping("testLimit")
    public String testLimit(){
        return "ok";
    }

    // 限流降级
    public String exceptionHandler(BlockException ex) {

        ex.printStackTrace();
        System.out.println("限流了...");
        return "限流了。。。。。。";
    }

    // 熔断降级，参数和返回值与源方法一致
    public String getByIdfallback(){

        System.out.println("降级了");
        return "限流降级";
    }
}
